package com.jing.controller;

import com.jing.pojo.FeedBack;
import com.jing.pojo.Result;
import com.jing.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 陈书憬
 * @version 1.0
 * 2024/9/13
 * 留言区
 */

@RestController
@RequestMapping("/feedback")
public class FeedBackController {

    @Autowired
    private FeedBackService feedBackService;

    /**
     * 列出所有用户留言
     *
     * @return
     */
    @GetMapping
    public Result<List<FeedBack>> feedback_list() {
        List<FeedBack> feedBackList = feedBackService.list();
        return Result.success(feedBackList);
    }

    /**
     * 用户发送添加留言
     *
     * @param feedBack
     * @return
     */
    @PostMapping("/send")
    public Result<String> submitFeedback(@RequestBody FeedBack feedBack) {
        Integer userId = feedBack.getId();
        String nickname = feedBack.getNickname();
        String message = feedBack.getMessage();
        feedBackService.save(userId, nickname, message);
        // 处理接收到的反馈信息，比如保存到数据库
        System.out.println("Received feedback from ID: " + userId + ", Nickname: " + nickname + ", Message: " + message);

        // 返回成功响应
        return Result.success("Feedback received successfully!");
    }

}
